<template>
	<view class="body">
		<view class="formdata">
			<view class="formdata-item">
				<view class="text">
					<text>班级名称</text>
				</view>
				<view class="input">
					<input placeholder="请输入班级名称" @input="OnClassName" />
				</view>
			</view>
		</view>
		<scroll-view scroll-x="true">
			<view class="table-lists">
				<view class="table-title">
					<view class="">班级ID</view>
					<view class="">班级名称</view>
					<view class="">专业名称</view>
				</view>

				<view class="table-item">
					<view v-for="item in DAT" :key="item.CLASS_ID" @tap="handleto(item.CLASS_ID)">
						<view class="">{{item.CLASS_ID}}</view>
						<view class="" style="text-decoration: underline;color: blue;">{{item.CLASSNAME}}</view>
						<view class="">{{item.MAJOR_NAME}}</view>
					</view>
				</view>
			</view>
		</scroll-view>
		<view v-if="!DAT.length" class="text-sm text-center">-- 暂无数据 --</view>
		<view class="cu-form-group" v-if="COUNT>1">
			<view class="title" @tap="firstPage()"><text class="check-info-btn">首页</text></view>
			<view class="title" @tap="lastPage()"><text class="check-info-btn">上一页</text></view>
			<view class="title">{{Page}}/{{COUNT}}</view>
			<view class="title" @tap="nextPage()"><text class="check-info-btn">下一页</text></view>
			<view class="title" @tap="endPage()"><text class="check-info-btn">尾页</text></view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import {onMounted,reactive,ref} from "vue"
	import {onLoad} from "@dcloudio/uni-app";
	import {useSyllabusList} from "./usesyllabus"
	const {		
		DAT,
		COUNT,
		initSyllabusList
	} = useSyllabusList()
	let Page = ref < any > ("1")
	let ClassName = ref < any > ("")
	function OnClassName(e:any){
		ClassName.value = e.detail.value
		Page.value = "1"
		initSyllabusList({
			ClassName: ClassName.value,
			Page:"1",
			PageSize: "10"
		})
	}
	function firstPage() {
		Page.value = "1"
		initSyllabusList({
			ClassName: ClassName.value,
			Page: Page.value,
			PageSize: "10"
		})
	}

	function lastPage() {
		if (Page.value > 1) {
			Page.value--
			initSyllabusList({
				ClassName: ClassName.value,
				Page: Page.value,
				PageSize: "10"
			})
		}
	}

	function nextPage() {
		if (Page.value < COUNT.value) {
			Page.value++
			initSyllabusList({
				ClassName: ClassName.value,
				Page: Page.value,
				PageSize: "10"
			})
		}
	}

	function endPage() {
		Page.value = COUNT.value
		initSyllabusList({
			ClassName: ClassName.value,
			Page: COUNT.value,
			PageSize: "10"
		})
	}
	function handleto(CLASS_ID:string){
		uni.navigateTo({
			url:`/pages/Syllabus/Detail?CLASS_ID=${CLASS_ID}`
		})
	}
	onLoad((option: any) => {
		initSyllabusList({
			ClassName: "",
			Page: "1",
			PageSize: "10",
		})
	})
</script>

<style lang="scss">
	.body {
		width: 100%;
		height: 100%;
		background-color: white;
	}

	.formdata {
		.formdata-item {
			padding: 0 32rpx 0 32rpx;
			border-bottom: 4rpx #F7F8FC solid;
			width: 100%;
			height: 110rpx;
			display: flex;
			align-items: center;

			.text {
				margin-right: 32rpx;
			}
		}
	}

	.flex {
		padding: 0 32rpx 0 32rpx;
		width: 750rpx;
		height: 110rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.table-title-bg {
		background-color: #dddd;
	}

	.state {
		text {
			background-color: #dbdcdf;
			color: white;
			padding: 5rpx;
			font-size: 20rpx
		}
	}

	.table {}

	.table-lists {
		display: flex;
		flex-direction: column;
		width: 1000rpx;
		font-size: 24rpx;

		.table-title {
			width: 100%;
			display: flex;
			height: 120rpx;
			font-weight: 600;
			background-color: #DDDDDD;
			color: #585850;

			view {
				padding: 10rpx;
				flex: 1;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}

		.table-item {
			width: 100%;
			display: flex;
			flex-direction: column;

			view {
				width: 100%;
				display: flex;
				height: 100rpx;

				view {
					color: #666666;
					flex: 1;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}
		}
	}
</style>
